<template>
  <div>
        <el-form :model="form"  ref="form" label-width="120px">
          
          <el-form-item label="发货方式" prop="delivery_type">
            <el-radio-group v-model="tt" size="small">
              <el-radio label="1">普通发货</el-radio>
              <el-radio label="2">快递e100发货</el-radio>
            </el-radio-group>
          </el-form-item>
          <div v-if="tt==1">
              <el-form-item label="物流名称" prop="logistics_name">
                <el-input v-model="form.deliveryName" placeholder="请输入物流名称" size="small"></el-input>
               </el-form-item>
               <el-form-item label="物流编号" prop="kuaidinum">
                <el-input v-model="form.kuaidinum" placeholder="请输入物流编号" size="small"></el-input>
               </el-form-item>
          </div>
          <div v-if="tt==2">
                <el-form-item label="物流名称" prop="kuaidicode">
                    <el-select v-model="form.kuaidicode" placeholder="请选择物流名称" size="small" filterable clearable>
                        <el-option v-for="item in options" :key="item.express_code" 
                            :label="item.company_name" 
                            :value="item.company_code"></el-option>
                    </el-select>
               </el-form-item>
               <el-form-item label="发货人" prop="sendName">
                <el-input v-model="form.sendName" placeholder="请输入发货人姓名" size="small"></el-input>
               </el-form-item>
               <el-form-item label="发货人手机号" prop="sendPhone">
                <el-input v-model="form.sendPhone" placeholder="请输入发货人手机号" size="small"></el-input>
               </el-form-item>
               <el-form-item label="发货人地址" prop="sendAddress">
                <el-input v-model="form.sendAddress" placeholder="请输入发货人地址" size="small"></el-input>
               </el-form-item>
          </div>
          <el-form-item label="" prop="sendAddress">
                <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
          </el-form-item>
        </el-form>

  </div>
</template>
<script>
export default {
  data() {
    return {
      form:{
            kuaidinum:"",
            deliveryName:"",
            kuaidicode:"",
            sendName:"",
            sendPhone:"",
            sendAddress:"",
            showAddressId:"",
      },
      tt:'1', // 1普通发货 2 快递e100发货
      options:[]
    };
  },
  props:{
    ttype:{
      type:String,
      default:'1'
    },
    orderId:{
      type:String,
      default:''
    },
    addressId:{
      type:Number,
      default:0
    }
  },
  mounted() {
    this.loadLogisticsCode()
  },
  methods:{
    loadLogisticsCode(){
        this.$api.post('/api/getExpressList').then(res=>{
            this.options = res.data
        })
    },
    confirm(){
        if(this.tt==1){  // 1普通发货 2 快递e100发货
             let params = {
                type:this.ttype,
                kuaidinum:this.form.kuaidinum,
                deliveryName:this.form.deliveryName,
                order_ids:this.orderId,
             }
            this.$api.post('/api/expressNomer',params).then(res=>{
                if(res.code==200){
                    this.$message.success('发货成功')
                    this.$emit('sendConfirm')
                }
            })
        }else{
             if(!this.addressId){
                this.$message.warning('收货人未填写地址不能发货')
                return
             }
             let params = {
                type:this.ttype,
                order_ids:this.orderId,
                kuaidicode:this.form.kuaidicode,
                sendName:this.form.sendName,
                sendPhone:this.form.sendPhone,
                sendAddress:this.form.sendAddress,
                showAddressId:this.addressId,
             }
            this.$api.post('/api/expressE100',params).then(res=>{
                if(res.code==200){
                    this.$message.success('发货成功')
                    this.$emit('sendConfirm')
                }
            })
        }
       
    },
  },
}
</script>
